package com.happy.unitconvert.model;

import com.happy.unitconvert.model.enums.UnitType;
import io.swagger.v3.oas.annotations.media.Schema;

import java.math.BigDecimal;

/**
 * 单位定义模型
 */
@Schema(description = "单位定义")
public class UnitDefinition {

  @Schema(description = "单位代码", example = "meter")
  private String code;

  @Schema(description = "单位名称", example = "米")
  private String name;

  @Schema(description = "单位符号", example = "m")
  private String symbol;

  @Schema(description = "单位类型")
  private UnitType unitType;

  @Schema(description = "转换为基础单位的系数", example = "1.0")
  private BigDecimal conversionFactor;

  @Schema(description = "转换偏移量（主要用于温度）", example = "0.0")
  private BigDecimal conversionOffset;

  @Schema(description = "是否为基础单位", example = "true")
  private boolean isBaseUnit;

  @Schema(description = "单位描述", example = "国际单位制中长度的基本单位")
  private String description;

  public UnitDefinition() {
    this.conversionOffset = BigDecimal.ZERO;
    this.isBaseUnit = false;
  }

  public UnitDefinition(String code, String name, String symbol, UnitType unitType,
      BigDecimal conversionFactor) {
    this();
    this.code = code;
    this.name = name;
    this.symbol = symbol;
    this.unitType = unitType;
    this.conversionFactor = conversionFactor;
  }

  public UnitDefinition(String code, String name, String symbol, UnitType unitType,
      BigDecimal conversionFactor, BigDecimal conversionOffset) {
    this(code, name, symbol, unitType, conversionFactor);
    this.conversionOffset = conversionOffset;
  }

  // Getters and Setters
  public String getCode() {
    return code;
  }

  public void setCode(String code) {
    this.code = code;
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public String getSymbol() {
    return symbol;
  }

  public void setSymbol(String symbol) {
    this.symbol = symbol;
  }

  public UnitType getUnitType() {
    return unitType;
  }

  public void setUnitType(UnitType unitType) {
    this.unitType = unitType;
  }

  public BigDecimal getConversionFactor() {
    return conversionFactor;
  }

  public void setConversionFactor(BigDecimal conversionFactor) {
    this.conversionFactor = conversionFactor;
  }

  public BigDecimal getConversionOffset() {
    return conversionOffset;
  }

  public void setConversionOffset(BigDecimal conversionOffset) {
    this.conversionOffset = conversionOffset;
  }

  public boolean isBaseUnit() {
    return isBaseUnit;
  }

  public void setBaseUnit(boolean baseUnit) {
    isBaseUnit = baseUnit;
  }

  public String getDescription() {
    return description;
  }

  public void setDescription(String description) {
    this.description = description;
  }

  @Override
  public String toString() {
    return "UnitDefinition{" +
        "code='" + code + '\'' +
        ", name='" + name + '\'' +
        ", symbol='" + symbol + '\'' +
        ", unitType=" + unitType +
        ", conversionFactor=" + conversionFactor +
        ", conversionOffset=" + conversionOffset +
        ", isBaseUnit=" + isBaseUnit +
        ", description='" + description + '\'' +
        '}';
  }
}
